package leetcode.dp;

/**
 * @author mazouri
 * @create 2021-09-20 23:34
 */
public class _121_maxProfit {
    public int maxProfit(int[] prices) {
        int res=0;
        int min = prices[0];

        for (int i = 1; i < prices.length; i++) {
            if (prices[i]<min) min = prices[i];
            else if ((prices[i]-min)>res) res = prices[i]-min;
        }

        return res;
    }

    public static void main(String[] args) {
        System.out.println(new _121_maxProfit().maxProfit(new int[]{7, 1, 5, 3, 6, 4}));
    }
}
